<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <router-link to="/user">user</router-link>
        <router-link to="/register">register</router-link>
        <router-view></router-view>
    </div>
</body>
<script src="lib/vue_2.5.22.js"></script>
<script src="lib/vue-router_3.0.2.js"></script>



<script>
    // 嵌套路由:在路由组件模板内部再次书写路由
    //在register组件中添加两个子路由链接
    // 添加子路由填充位置
    // 定义子路由组件
    // 配置子路由规则


    const User = {
        template: '<h1>user</h1>'
    }

    const Register = {
        template: `
        <div>
            <div>register</div>
            <router-link to="/register/tab1">tab1</router-link>
            <router-link to="/register/tab2">tab2</router-link>
            
            <router-view></router-view>
        </div>
        `
    }
    const tab1 = {
        template: '<h1>tab1</h1>'
    }
    const tab2 = {
        template: '<h1>tab2</h1>'
    }
    var myrouter = new VueRouter({
        routes: [{
            // 路由重定向
            path: '/',
            redirect: '/user'
        }, {
            path: '/user',
            component: User
        }, {
            path: '/register',
            component: Register,
            children: [{
                // 子路由重定向
                path: '/register',
                redirect: '/register/tab1'
            }, {
                path: '/register/tab1',
                component: tab1
            }, {
                path: '/register/tab2',
                component: tab2
            }]
        }]
    })

    // 把创建的路由对象挂载到vm实例上
    var vm = new Vue({
        el: '#app',
        router: myrouter

    })
</script>

</html>